package com.yuyang.wifi.activitys;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;

import android.preference.PreferenceManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.kwad.sdk.api.SdkConfig;
import com.umeng.analytics.MobclickAgent;
import com.yuyang.wifi.R;
import com.yuyang.wifi.SplashActivity;
import com.yuyang.wifi.activitys.mine.HintClickActivity;
import com.yuyang.wifi.base.AppManager;
import com.yuyang.wifi.base.BaseActivity;
import com.yuyang.wifi.base.BaseFragment;
import com.yuyang.wifi.base.BaseResult;
import com.yuyang.wifi.base.Constants;
import com.yuyang.wifi.base.TestPosId;
import com.yuyang.wifi.constant.AppConstant;
import com.yuyang.wifi.constant.ConstantsMsg;
import com.yuyang.wifi.fragment.ContractTabFragment;
import com.yuyang.wifi.fragment.TodayHotTabFragment;
import com.yuyang.wifi.jobservice.AppService;
import com.yuyang.wifi.jobservice.KeepAliveJobService;
import com.yuyang.wifi.model.AdTypeInfoModel;
import com.yuyang.wifi.model.AdTypeInfoResult;
import com.yuyang.wifi.model.ShowIconResult;
import com.yuyang.wifi.utils.ActivityAllManager;
import com.yuyang.wifi.utils.DatePickerUtil;
import com.yuyang.wifi.utils.GetIPAdsUtil;
import com.yuyang.wifi.utils.GetMacAdsUtil;
import com.yuyang.wifi.utils.MPermissionUtils;
import com.yuyang.wifi.utils.NetworkUtil;
import com.yuyang.wifi.utils.PreferencesProviderUtils;
import com.yuyang.wifi.utils.RxUtil;
import com.yuyang.wifi.utils.SpUtil;
import com.yuyang.wifi.utils.ToastUtils;
import com.yuyang.wifi.utils.eventbus.BaseEvent;
import com.yuyang.wifi.utils.eventbus.BaseEventManager;
import com.yuyang.wifi.utils.network.BaseDataSubscriber;
import com.yuyang.wifi.utils.network.HttpErrorHandler;
import com.yuyang.wifi.utils.network.HttpManager;
import com.yuyang.wifi.utils.network.RxDataInstance;
import com.yuyang.wifi.views.LoadCSJiliVideoUtils;
import com.yuyang.wifi.views.LoadCsjNewInsertFullAdUtils;
import com.yuyang.wifi.views.LoadYLHJiliVideoUtils;
import com.yuyang.wifi.views.MittUtils;
import com.kwad.sdk.api.KsAdSDK;
import com.kwad.sdk.api.KsContentPage;
import com.kwad.sdk.api.KsScene;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import butterknife.BindView;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static com.blankj.utilcode.util.DeviceUtils.getMacAddress;

/*
 * 首页
 * */

public class NewMainHomeActivity extends BaseActivity {

    FragmentManager mFragmentManager;
    @BindView(R.id.rg_bottom_bar)
    RadioGroup rgBottomBar;
    @BindView(R.id.rb_bar_save_money)
    RadioButton rbBarSaveMoney;
    @BindView(R.id.rb_bar_contract)
    RadioButton rbBarSignIn;
    @BindView(R.id.rb_bar_mine)
    RadioButton rbBarMine;
    private ContractTabFragment contractTabFragment;
    private TodayHotTabFragment todayHotTabFragment;
    public BaseFragment currentFragment;
    private InnerRecevier innerReceiver;

    private KsContentPage mKsContentPage;
    private Fragment mineTabFragment = null;
    private LoadCsjNewInsertFullAdUtils newInsertFullAd;
    private static final String APP_KEY = "831899f8-567c-4e75-8922-7f345bb57f7c";
    private static final String APP_WB_KEY = "cK7PgwbAr";
    private String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
    private boolean isShow;
    private String mOaid;
    private String mEventtype = "0";
    private LoadYLHJiliVideoUtils loadYLHJiliVideoUtils;

    @Override
    protected void initActionBar() {

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_new_main_home;
    }

    @Override
    protected void initContentView() {
        isShow = true;
        initSDK(this);
        switchContent(R.id.rb_bar_contract);
        int tabId = getIntent().getIntExtra("tab", 0);
        if (tabId != 0) {
            ((RadioButton) findViewById(tabId)).setChecked(true);
        }
        initContentPage();
        rgBottomBar.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switchContent(checkedId);
            }
        });
    }

    public void initSDK(Context appContext) {
        try {
            KsAdSDK.init(appContext, new SdkConfig.Builder()
                    .appId(ConstantsMsg.KS_APP_ID) // 测试aapId，请联系快手平台申请正式AppId，必填
                    .appName("随身WiFi") // 测试appName，请填写您应用的名称，非必填
                    .appKey(APP_KEY) // 直播sdk安全验证，接入直播模块必填
                    .appWebKey(APP_WB_KEY) // 直播sdk安全验证，接入直播模块必填
                    // Feed和入口组件，夜间模式样式配置，如果不配置 默认是"ks_adsdk_night_styles.xml"
                    .nightThemeStyleAssetsFileName("ks_adsdk_night_styles.xml")
                    .showNotification(true) // 是否展示下载通知栏
                    .debug(true)
                    .build());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取内容联盟广告接口
     */
    private void initContentPage() {
        KsScene ksScene = new KsScene.Builder(TestPosId.POSID_CONTENT_PAGE.posId).build();
        mKsContentPage = KsAdSDK.getLoadManager().loadContentPage(ksScene);
        initListener(mKsContentPage);
    }

    // onNewIntent（）非常好用，Activity第一启动的时候执行onCreate()---->onStart()---->onResume()等后续生命周期函数，也就时说第一次启动Activity并不会执行到onNewIntent().
    // 而后面如果再有想启动Activity的时候，那就是执行onNewIntent()---->onResart()------>onStart()----->onResume().
    //searchActivity启动该页的时候是cleartop+singletop模式，所以会把这个页面推到顶部
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
    }

    private void switchContent(int checkedId) {
        mFragmentManager = getSupportFragmentManager();
        hideAllFragment();
        FragmentTransaction transaction = mFragmentManager.beginTransaction();
        switch (checkedId) {
            case R.id.rb_bar_save_money:
                if (todayHotTabFragment == null) {
                    todayHotTabFragment = TodayHotTabFragment.newInstance();
                }
                if (mFragmentManager.findFragmentByTag("home") == null) {
                    transaction.add(R.id.content, todayHotTabFragment, "home");
                }
                if (todayHotTabFragment.isHidden()) {
                    transaction.show(todayHotTabFragment);
                }
                currentFragment = todayHotTabFragment;
                break;
            case R.id.rb_bar_contract:
                if (contractTabFragment == null) {
                    contractTabFragment = ContractTabFragment.newInstance();
                }
                if (mFragmentManager.findFragmentByTag("wifi") == null) {
                    transaction.add(R.id.content, contractTabFragment, "wifi");
                }
                if (contractTabFragment.isHidden()) {
                    transaction.show(contractTabFragment);
                }
                currentFragment = contractTabFragment;
                SpUtil.saveOrUpdate(AppConstant.KEY_JUMP_TYPE_TAB, "");
                break;
            case R.id.rb_bar_mine:
                if (mineTabFragment == null) {
                    mineTabFragment = mKsContentPage.getFragment();
                }
                if (mFragmentManager.findFragmentByTag("mine") == null) {
                    transaction.add(R.id.content, mineTabFragment, "mine");
                }
                if (mineTabFragment.isHidden()) {
                    transaction.show(mineTabFragment);
                }
                // currentFragment = mineTabFragment;
                break;
            default:
                break;
        }
        transaction.commit();

    }

    private void hideAllFragment() {
        FragmentTransaction transaction = mFragmentManager.beginTransaction();
        if (todayHotTabFragment != null) {
            transaction.hide(todayHotTabFragment);
        }

        if (contractTabFragment != null) {
            transaction.hide(contractTabFragment);
        }

        if (mineTabFragment != null) {
            transaction.hide(mineTabFragment);
        }
        // transaction.commit();
        transaction.commitAllowingStateLoss();
    }

    @Override
    protected void onResume() {
        super.onResume();

//        if (null == newInsertFullAd) {
//            newInsertFullAd = LoadCsjNewInsertFullAdUtils.getInstance();
//            newInsertFullAd.load(this, "csj_jl_quit");
//        }
//        newInsertFullAd.setItemAllClickListener(new LoadCsjNewInsertFullAdUtils.OnItemAllClickListener() {
//            @Override
//            public void onItemAllClickListener() {
//                finish();
//                AppManager.getInstance().finishAllActivity();
//            }
//        });
//        loadYLHJiliVideoUtils = LoadYLHJiliVideoUtils.getInstance();
//        loadYLHJiliVideoUtils.load(this, "ylh_jl_quit");
//        loadYLHJiliVideoUtils.play();
//        loadYLHJiliVideoUtils.setAdCloseListener(new LoadYLHJiliVideoUtils.OnAdCloseListener() {
//            @Override
//            public void onAdCloseListenerListener(boolean isPlayComplete) {
//
//
//            }
//        });
        registerBroadcastReceiver();
        //变现猫 绑定⽤户数据
        String userId = SpUtil.find(AppConstant.KEY_USER_ID);
        mOaid = SpUtil.find(AppConstant.KEY_OAID);
        if (TextUtils.isEmpty(mOaid)) {
            new MittUtils().getDeviceIds(this, new MittUtils.AppIdsUpdater() {
                @Override
                public void OnIdsAvailed(boolean isSupport, String oaid) {
                    SpUtil.saveOrUpdate(AppConstant.KEY_OAID, oaid);
                    mOaid = oaid;
                    Log.e("参数", "oaid:=== " + oaid);
                }
            });
        }
        // JobScheduler 拉活
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            KeepAliveJobService.startJob(this);
//        }
//
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            startForegroundService(new Intent(this, AppService.class));
        } else {
            startService(new Intent(this, AppService.class));
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            KeepAliveJobService.startJob(this);
        }

        boolean isAllGranted = checkPermissionAllGranted(permissions);
        if (!isPagerServiceRunning()) {
            Log.e("TAG", "onResume:==== " + isAllGranted + "  isShow" + isShow);
            if (isAllGranted && isShow) {
                isShow = false;
                Intent intent = new Intent(NewMainHomeActivity.this, HintClickActivity.class);
                intent.putExtra("mJumpType", "splash");
                startActivity(intent);
            }
        }
        registerInto();
        ttCallBack();
    }

    private boolean checkPermissionAllGranted(String[] permissions) {
        for (String permission : permissions) {
            if (ContextCompat.checkSelfPermission(NewMainHomeActivity.this, permission) != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
    }


    private boolean isPagerServiceRunning() {
        ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if ("com.yuyang.wifi.service.LiveWallpaperService".equals(service.service.getClassName())) {
                return true;
            }
        }
        return false;
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (null != innerReceiver) {
            Log.e("broadReceive====", "onPause: ===unregisterReceiver");
            getApplicationContext().unregisterReceiver(innerReceiver);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    //手机连续按返回键两次的间隔时间
    private long mExitTime;

    //按系统返回键时出发
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if ((System.currentTimeMillis() - mExitTime) > 2000) {
                Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
                mExitTime = System.currentTimeMillis();
            } else {
                BaseEventManager.post(null, "hint_icon");//发送eventbus消息通知
                MobclickAgent.onKillProcess(this);//程序退出时，用于保存统计数据的API。
                ToastUtils.cancelToast();
                finish();
                AppManager.getInstance().finishAllActivity();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

//    @Override
//    public void onBackPressed() {
//        getAdTypeInfo();
//    }

    private void registerBroadcastReceiver() {
        Log.e("broadReceive====", "onRegister: ===onResume");
        //创建广播
        innerReceiver = new InnerRecevier();
        //动态注册广播
        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        //启动广播
        getApplicationContext().registerReceiver(innerReceiver, intentFilter);
    }

    private class InnerRecevier extends BroadcastReceiver {

        final String SYSTEM_DIALOG_REASON_KEY = "reason";

        final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";

        final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";

        @Override
        public void onReceive(Context context, Intent intent) {

            if (null != intent) {
                String action = intent.getAction();
                if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
                    String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
                    if (reason != null) {
                        if (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS) || reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)
                                || reason.equals("fs_gesture")) {
                            Log.e("TAG", "reason:===== " + reason);
                            // showIcon();
                            String changeIcon = PreferencesProviderUtils.getString(NewMainHomeActivity.this,
                                    "change_icon", AppConstant.KEY_CHANGE_ICON, "");
                            if (!TextUtils.isEmpty(changeIcon) && "change_icon".equals(changeIcon)) {
                                BaseEventManager.post(null, "hint_icon");//发送eventbus消息通知
                            }
                            ActivityAllManager.getInstance().finishAllActivity();
                            //Toast.makeText(SignInRedBagActivity.this, "Home键被监听", Toast.LENGTH_SHORT).show();
                        } else if (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
                            // Toast.makeText(SignInRedBagActivity.this, "多任务键被监听", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            }
        }
    }

    private void showIcon() {
        RxDataInstance.getInstance().initMap(NewMainHomeActivity.this);
        HttpManager.getInstance().getApi().showIcon(RxDataInstance.getInstance().getParamMap())
                .compose(RxUtil.<ShowIconResult>bindLifecycleAndApplySchedulers(this))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseDataSubscriber<ShowIconResult>(new HttpErrorHandler() {
                    @Override
                    public void onHttpError(BaseResult result) {
                        com.yuyang.wifi.utils.ToastUtils.showShortToast(NewMainHomeActivity.this, result.getErrorMessage());
                    }

                    @Override
                    public void onHttpException(Throwable e) {
                        // dismissLoadingDialog();
                    }
                }) {
                    @Override
                    public void onDataNext(ShowIconResult result) {
                        int resultCode = result.getResultCode();
                        if (0 == resultCode) {
                            // changeLuncher();
                            BaseEventManager.post(null, "hint_icon");//发送eventbus消息通知
                        } else {
                            ToastUtils.showShortToast(NewMainHomeActivity.this, result.getErrorMessage());
                        }
                    }
                });

    }


    private void registerInto() {
        String mac = GetMacAdsUtil.getMac(NewMainHomeActivity.this);
        String ipAddress = GetIPAdsUtil.getIPAddress(NewMainHomeActivity.this);
        String androidid = getAndroidId(NewMainHomeActivity.this);
        String imei = getDeviceIds(NewMainHomeActivity.this);
        Log.e("参数", "mac:=== " + mac);
        Log.e("参数", "ipAddress:=== " + ipAddress);
        Log.e("参数", "imei:=== " + imei);
        Log.e("参数", "androidid:=== " + androidid);
        RxDataInstance.getInstance().initMap(NewMainHomeActivity.this)
                .put("imei", imei)
                .put("oaid", mOaid)
                .put("idfa", "")
                .put("androidid", androidid)
                .put("mac", mac)
                .put("ip", ipAddress);
        HttpManager.getInstance().getApi().registerInto(RxDataInstance.getInstance().getParamMap())
                .compose(RxUtil.<BaseResult>bindLifecycleAndApplySchedulers(this))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseDataSubscriber<BaseResult>(new HttpErrorHandler() {
                    @Override
                    public void onHttpError(BaseResult result) {

                    }

                    @Override
                    public void onHttpException(Throwable e) {
                        // dismissLoadingDialog();
                    }
                }) {
                    @Override
                    public void onDataNext(BaseResult result) {
                        int resultCode = result.getResultCode();

                    }
                });

    }


    private void ttCallBack() {
        String mac = GetMacAdsUtil.getMac(NewMainHomeActivity.this);
        String ipAddress = GetIPAdsUtil.getIPAddress(NewMainHomeActivity.this);
        String androidid = getAndroidId(NewMainHomeActivity.this);
        String imei = getDeviceIds(NewMainHomeActivity.this);
        Log.e("参数", "mac:=== " + mac);
        Log.e("参数", "ipAddress:=== " + ipAddress);
        Log.e("参数", "imei:=== " + imei);
        Log.e("参数", "androidid:=== " + androidid);

        Long spacerDay = DatePickerUtil.getSpacerDay();
        if (null != spacerDay && spacerDay == 1) {
            mEventtype = "0";
        } else {
            mEventtype = "6";
        }
        RxDataInstance.getInstance().initMap(NewMainHomeActivity.this)
                .put("imei", imei)
                .put("oaid", mOaid)
                .put("idfa", "")
                .put("androidid", androidid)
                .put("eventtype", mEventtype);
        HttpManager.getInstance().getApi().ttCallBack(RxDataInstance.getInstance().getParamMap())
                .compose(RxUtil.<BaseResult>bindLifecycleAndApplySchedulers(this))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseDataSubscriber<BaseResult>(new HttpErrorHandler() {
                    @Override
                    public void onHttpError(BaseResult result) {
                    }

                    @Override
                    public void onHttpException(Throwable e) {
                        // dismissLoadingDialog();
                    }
                }) {
                    @Override
                    public void onDataNext(BaseResult result) {
                        int resultCode = result.getResultCode();

                    }
                });

    }

    private static String getAndroidId(Context context) {
        String deviceID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
        if (!TextUtils.isEmpty(deviceID)) {
            return deviceID;
        }
        return deviceID;
    }

    //获取设备ID
    public static String getDeviceIds(Context context) {

        try {
            TelephonyManager telephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            if (telephonyMgr != null) {
                if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
                    return "";
                }
                String deviceId = telephonyMgr.getDeviceId();
                //Log.e("channel", "onViewClicked:" + deviceId);
                return deviceId;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return "";
    }


    /**
     * 修改App icon
     * Created by ysr on 2017/10/10 14:05.
     * 邮箱 yangshirong@log56.com
     */
    private void changeLuncher() {
        String name = "com.ysr.appiconchange.newsLuncherActivity";
        PackageManager pm = getPackageManager();
        //去除旧图标，不去除的话会出现2个App图标
        pm.setComponentEnabledSetting(getComponentName(),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
        //显示新图标
        pm.setComponentEnabledSetting(new ComponentName(NewMainHomeActivity.this, name),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

        //Intent 重启 Launcher 应用
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        List<ResolveInfo> resolves = pm.queryIntentActivities(intent, 0);
        for (ResolveInfo res : resolves) {
            if (res.activityInfo != null) {
                android.app.ActivityManager am = (android.app.ActivityManager) getSystemService(ACTIVITY_SERVICE);
                am.killBackgroundProcesses(res.activityInfo.packageName);
            }
        }
        Toast.makeText(this, "桌面图标已更换", Toast.LENGTH_LONG).show();
    }


    private void initListener(KsContentPage ksContentPage) {
        // 接口回调在主线程，误做耗时操作
        ksContentPage.setPageListener(new KsContentPage.PageListener() {
            @Override
            public void onPageEnter(KsContentPage.ContentItem item) {
                Log.e("ContentPage", "position: " + item.position + "页面Enter");
                setFloatingPageStatus(item, "Enter");
            }

            @Override
            public void onPageResume(KsContentPage.ContentItem item) {
                Log.e("ContentPage", "position: " + item.position + "页面Resume");
                setFloatingPageStatus(item, "Resume");
            }


            @Override
            public void onPagePause(KsContentPage.ContentItem item) {
                Log.e("ContentPage", "position: " + item.position + "页面Pause");
                setFloatingPageStatus(item, "Pause");
            }

            @Override
            public void onPageLeave(KsContentPage.ContentItem item) {
                Log.e("ContentPage", "position: " + item.position + "页面Leave");
                setFloatingPageStatus(item, "Leave");
            }

        });

        // 接口回调在主线程，误做耗时操作
        ksContentPage.setVideoListener(new KsContentPage.VideoListener() {
            @Override
            public void onVideoPlayStart(KsContentPage.ContentItem contentItem) {

            }

            @Override
            public void onVideoPlayPaused(KsContentPage.ContentItem contentItem) {

            }

            @Override
            public void onVideoPlayResume(KsContentPage.ContentItem contentItem) {

            }

            @Override
            public void onVideoPlayCompleted(KsContentPage.ContentItem contentItem) {

            }

            @Override
            public void onVideoPlayError(KsContentPage.ContentItem contentItem, int i, int i1) {

            }


        });

        ksContentPage.setShareListener(new KsContentPage.KsShareListener() {
            @Override
            public void onClickShareButton(String shareData) {
                Log.d("ContentPage",
                        "TestContentAllianceTabLayoutActivity onClickShareButton shareData: " + shareData);
                // showTestFragment1(new JSONObject(shareData));
            }
        });
    }

    @SuppressLint("SetTextI18n")
    private void setFloatingPageStatus(KsContentPage.ContentItem item, String pageStatus) {
        //  mItemPosition.setText("item position: " + item.position);
        String type;
//        if (item.materialType == ContentItem.MaterialType.CONTENT) {
//            type = "content";
//        } else if (item.materialType == ContentItem.MaterialType.AD) {
//            type = "ad";
//        } else if (item.materialType == ContentItem.MaterialType.THIRD_AD) {
//            type = "third ad";
//        } else {
//            type = "unknown";
//        }
//        mItemType.setText("item type: " + type);
//        mItemPageStatus.setText("item page: " + pageStatus);
    }


    @SuppressLint("SetTextI18n")
    private void setFloatingVideoStatus(String videoStatus) {
        // mItemVideoStatus.setText("item videoStatus: " + videoStatus);
    }


    private void getAdTypeInfo() {
        RxDataInstance.getInstance().initMap(NewMainHomeActivity.this)
                .put("entryNumber", "10");
        HttpManager.getInstance().getApi().getAdTypeInfo(RxDataInstance.getInstance().getParamMap())
                .compose(RxUtil.<AdTypeInfoResult>bindLifecycleAndApplySchedulers(this))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseDataSubscriber<AdTypeInfoResult>(new HttpErrorHandler() {
                    @Override
                    public void onHttpError(BaseResult result) {
                        ToastUtils.showShortToast(NewMainHomeActivity.this, result.getErrorMessage());
                    }

                    @Override
                    public void onHttpException(Throwable e) {
                        // dismissLoadingDialog();
                    }
                }) {
                    @Override
                    public void onDataNext(AdTypeInfoResult result) {
                        int resultCode = result.getResultCode();
                        if (0 == resultCode) {
                            AdTypeInfoModel data = result.getData();
                            if (null != data) {
                                int type = data.getType();
                                if (type == 1) {
                                    newInsertFullAd.showNewInterAd();
                                } else if (type == 2) {
                                    //initYLHAdAppId();
                                }
                            }
                        } else {
                            ToastUtils.showShortToast(NewMainHomeActivity.this, result.getErrorMessage());
                        }
                    }
                });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    @Override
    public void onMessageEventMain(BaseEvent baseEvent) {
        super.onMessageEventMain(baseEvent);
        String tagString = baseEvent.getTagString();
        switch (tagString) {

        }
    }
}
